﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace csharp_Movies_315.Models
{
    static public class TodoData
    {
      
        // guid
        // start at negative, so that the first item is 0
        static private int _counter = -1; // counter/guid


        // method to access the counter, via return
        public static int GetCount(){
            return _counter;
        }
        // method to modify the counter, increment by 1
        public static void AddCount()
        {
            _counter++;
        }
        // method to increment and return - generate the GUID
        public static int AssignCount(){
            AddCount();
            return _counter;
        }

        // list of TODOS
        private static List<Todo> _todos = new List<Todo>() {
        new Todo(){TodoId=AssignCount(), IsCompleted=false, Task="get Coffee"},
        new Todo(){TodoId=AssignCount(), IsCompleted=false, Task="drink Coffee"},
        new Todo(){TodoId=AssignCount(), IsCompleted=true, Task="happy hour"},
        new Todo(){TodoId=AssignCount(), IsCompleted=true, Task="recharge battery"}

        };

        // fetch the TODOS
        public static List<Todo> GetTodos()
        {
            return _todos;
        }

        // fetch a single Todo
        public static Todo GetTodo(int id)
        {
            return _todos.FirstOrDefault(t => t.TodoId == id);
        }

        // save changes after edit
        public static void SaveTodo(Todo editedTodo)
        {
            Todo temp = _todos.FirstOrDefault(t => t.TodoId == editedTodo.TodoId);
            temp.Task = editedTodo.Task;
            temp.IsCompleted = editedTodo.IsCompleted;
        }



        // add a todo
        public static void AddTodo(Todo TodoToAdd)
        {
            _todos.Add(TodoToAdd);
        }

        // delete
        public static void DeleteTodo(int id)
        {
            _todos.RemoveAt(id);
        }

    }
}